<?php

namespace App\Models\Applet\Other;

class AreasModel extends BaseOtherModel
{
    protected $table = 'areas';


    /**
     * 省市区列表
     * @param int $pid
     * @param array $fields
     * @return array
     */
    public function list(int $pid = 0, array $fields = self::QUERY_DEFAULT_FIELDS): array
    {
        return $this->select($fields)
                    ->where('pid', $pid)
                    ->where('deleted', self::DELETED_NO)
                    ->get()
                    ->toArray();
    }

    /**
     * 根据code获取省市区名称
     * @param array $codeList
     * @return mixed
     */
    public function getAreaNameByCode(array $codeList)
    {
        return $this->select(['name'])
                    ->whereIn('code', $codeList)
                    ->where('deleted', self::DELETED_NO)
                    ->get()
                    ->toArray();
    }

    /**
     * 根据code获取省市区列表
     * @param array $codeList
     * @return mixed
     */
    public function getAreaNameListByCodeList(array $codeList)
    {
        return $this->select(['code', 'name'])
                    ->whereIn('code', $codeList)
                    ->where('deleted', self::DELETED_NO)
                    ->get()
                    ->toArray();
    }
}
